<?php
class User extends enfasisDB{
	
	public function __construct(){
		parent::__construct();
	}
	/*
	* Metodo estatico de prueba 
	* return array
	*/
	public static function LoginUsr($user, $pass){
	 
		$db = enfasisDB::getinstance();     
		$sql = "SELECT COUNT(*) as total FROM user WHERE username = ? and password = ? LIMIT 1 ";   
		$st = $db->prepare( $sql );
	  
		$password = md5($pass);
		$st->bindParam(1,$user);
		$st->bindParam(2,$password);
		$row = $st->fetch();
		
		if($row['total'] == 0 ){
			header( "Location: ".BASE_URL );
			die();
		}
		else{
			$_SESSION['username'] = $row['username'];
			header("Location: ".BASE_URL."dashboard/");
			die();
		}
	}

	public static function OutLoginUsr(){
	 
		session_unregister('username');
		session_destroy();

		echo"<script type='text/javascript'>
				alert('Su sesion ha finalizado');
				window.location='index.php';
			</script>";	
	}	
}